#!/usr/bin/python

import os

td_cuts = [0., 0.02, 0.04, 0.06, 0.10, 0.12, 0.14, 0.16, 0.18, 0.20, 0.30, 0.40, 0.50]
hl_cuts = [0., 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90]

target_eff_DY     = [[0. for col in range(len(hl_cuts))] for row in range(len(td_cuts))]
target_ratio_DY   = [[0. for col in range(len(hl_cuts))] for row in range(len(td_cuts))]
target_eff_JPsi   = [[0. for col in range(len(hl_cuts))] for row in range(len(td_cuts))]
target_ratio_JPsi = [[0. for col in range(len(hl_cuts))] for row in range(len(td_cuts))]
random_eff        = [[0. for col in range(len(hl_cuts))] for row in range(len(td_cuts))]

for i in range(len(td_cuts)):
    for j in range(len(hl_cuts)):
        
        cmd_dy = './analyzeRoad DY_R964.root hists.root '+str(td_cuts[i])+' '+str(hl_cuts[j])
        cmd_jpsi = './analyzeRoad JPsi_R964.root hists.root '+str(td_cuts[i])+' '+str(hl_cuts[j])
	cmd_gun = './gunAnalyzer Gun_R925.root '+str(td_cuts[i])+' '+str(hl_cuts[j])

	dy_res = os.popen(cmd_dy).readlines()
	jpsi_res = os.popen(cmd_jpsi).readlines()
	gun_res = os.popen(cmd_gun).readlines()

        target_eff_DY[i][j] = float((dy_res[4].strip().split())[3])
        target_ratio_DY[i][j] = float((dy_res[6].strip().split())[8])
        target_eff_JPsi[i][j] = float((jpsi_res[4].strip().split())[3])
        target_ratio_JPsi[i][j] = float((jpsi_res[6].strip().split())[8])
	random_eff[i][j] = float((gun_res[3].strip().split())[0])

	print i, j
	print td_cuts[i], hl_cuts[j]
	print target_eff_DY[i][j], target_ratio_DY[i][j], target_eff_JPsi[i][j], target_ratio_JPsi[i][j], random_eff[i][j]
